home *** CD-ROM | disk | FTP | other *** search
- // lwc.cpp: Display count of lines and words
- #include <iostream.h>
- #include <strstream.h>
- #include <stddef.h>
-
- main()
- {
- const size_t BUFSIZ = 128;
- char s[BUFSIZ];
- size_t lc = 0, wc = 0;
-
- while (cin.getline(s,BUFSIZ))
- {
- ++lc;
- istrstream line(s);
- char word[BUFSIZ];
- while (line >> word)
- ++wc;
- }
-
- cout << "Lines: " << lc << ", words: " << wc << endl;
- return 0;
- }
-
- // Output from the statement "lwc < lwc.cpp"
- // Lines: 24, words: 63
-
-